<%@page contentType="text/html; charset=UTF-8" import="java.util.*,hotel.entity.Role" pageEncoding="UTF-8"%>
<%@include file="../link.html"%>
<!DOCTYPE html>
<script type="text/javascript">
$(document).ready(function() {
	$("#btn-close").click( function () { 
		var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		parent.layer.close(index); //再执行关闭 
	});

});

function saveUser(){
	var index=$('#btn-submit').attr('class').indexOf("disabled");
	var form = new FormData(document.getElementById("userForm"));
	if(index==-1){//disabled的下标为-1说明确定按钮可用
		$.ajax({
	        type:"post",
	        url:"addUser",
	        processData: false,  
	        contentType: false,
	        //data: $('#userForm').serialize(),//表单数据
	        data: form,
	        success: function(data){
				layer.msg('创建成功', {icon: 1, time: 800}, function(){//关闭后执行的操作
						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						parent.layer.close(index); //再执行关闭 
					});  
	        }
	    });
	}
	return false;
}

</script>

<div style="padding-top:25px;">
	<form id="userForm" action="addUser" method="post" class="form-horizontal" 
	data-toggle="validator" role="form" enctype="multipart/form-data">
		<div class="form-group">
			<label class="col-sm-4 control-label">登录账号<span style="color:red;">*</span></label>
			<div class="col-sm-5">
				<input id="account" name="account" class="form-control" autofocus="autofocus" required>
			</div>
			<div class="help-block with-errors"></div>
		</div>

		<div class="form-group">
			<label class="col-sm-4 control-label">密码<span style="color:red;">*</span></label>
			<div class="col-sm-5">
				<input id="password" type="password" name="password" class="form-control" required>
			</div>
			<div class="help-block with-errors"></div>
		</div>
		<div class="form-group">
			<label class="col-sm-4 control-label">重复密码</label>
			<div class="col-sm-5">
				<input id="passwordRepeat" type="password" class="form-control">
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-4 control-label">姓名<span style="color:red;">*</span></label>
			<div class="col-sm-5">
				<input id="name" name="name" class="form-control" required>
			</div>
			<div class="help-block with-errors"></div>
		</div>
		<div class="form-group">
			<label class="col-sm-4 control-label">性别</label>
			<div class="col-sm-1">
				<input type="radio" name="gender" class="iradio_minimal" checked value="男"> 男
			</div>
			<div class="col-sm-1">
				<input type="radio" name="gender" class="iradio_minimal" value="女"> 女
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-4 control-label">手机号码<span style="color:red;">*</span></label>
			<div class="col-sm-5">
				<input id="telephone" name="telephone" class="form-control" required>
			</div>
			<div class="help-block with-errors"></div>
		</div>
		<div class="form-group">
			<label class="col-sm-4 control-label">用户角色<span style="color:red;">*</span></label>
			<div class="col-sm-5">
				<select id="select" name="role.roleid" class="form-control">
					<%
					List<Role> list=(List<Role>)request.getAttribute("roleList");
					if(list!=null&&list.size()>0)
					for(Role r:list){
						out.print("<option value='"+r.getRoleid()+"'>"+r.getRoleName()+"</option>");
					}
					%>
				</select>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-4 control-label">用户头像</label>
			<div class="col-sm-5">
				<input type="file" name="user_image">
			</div>
		</div>
		
		<div class="box-footer"></div>
		
		<div class="form-group">
			<label class="col-sm-4 control-label"></label>
			<div class="col-sm-5">
				<div class="pull-right">
					<button id="btn-submit" type="submit" class="btn btn-primary" onClick="return saveUser()">
						<i class="fa fa-floppy-o "></i> 确定
					</button>
					<button id="btn-close" class="btn btn-close btn-primary" type="button">
						<i class="fa fa-remove"></i> 关闭
					</button>
				</div>
			</div>
		</div>
	</form>
</div>